<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>orderListEchart</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
</head>
<body>
    <div id="chartmain" style="width:700px; height: 500px;"></div>


<script src="/echart/echarts.min.js" charset="utf-8"></script>

<script>
    var option = {
        title: {
            text: '商品收益'
        },
        xAxis: {
            type: 'category',
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月'],
            name: '时间'
        },
        yAxis: {
            name: '收益',
            type: 'value',
            axisLabel: {
                formatter: '{value} 元'
            }
        },
        series: [{
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: 'line',
            //smooth: true,
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }],
        tooltip: {
            show: true,
            trigger: 'axis',
            formatter: "日期：{b}<br/>收益：{c} 元"
        },
        toolbox: {
            feature: {
                dataView: {
                    show: true,
                    readOnly: true
                },
                magicType: {
                    show: true,
                    type: ['line', 'bar']
                },
                restore: {
                    show: true
                },
                saveAsImage: {
                    show: true
                }
            }
        }
    };
        //初始化echarts实例
        var myChart = echarts.init(document.getElementById('chartmain'));
        //使用制定的配置项和数据显示图表
        myChart.setOption(option);
        initEchart();
    // $(function () {
    //     initEchart();
    //     // myChart.setOption({xAxis: {data: xAxisData}, series: {data: seriesData}})
    // })
    //
    function initEchart() {
        $.post('/order/orderListEchart',function (res) {
            console.log(res);
            var xAxisData = [];
            var seriesData = [];
            $.each(res.data,function (i,item) {
                xAxisData.push(item.month);
                seriesData.push(item.total);
            })
            myChart.setOption({xAxis: {data: xAxisData}, series: {data: seriesData}})
        })
    }
</script>
</body>
</html>